<?php

class indexAction extends T {


	/*
	function index () {
	
	
	$this->php->session()->init();
	//unset($this->session->openstart);
	
	var_dump($_SESSION);
	session_destroy();
	
	echo time();
		
		
	
	*/
	

	function index() {
	
		$this->php->loaddb()->loadview()->helper("function")->helper("newsurl")->init();
		
		//通过 M 处理业务
		$this->php->M("job")->job_tree();
		
		$zplist = $this->db->settable("job_zhaopin")->order("id desc")->limit(6)->select();
		$jllist = $this->db->settable("job_jianli")->order("id desc")->limit(6)->select();
		$newslist = $this->db->settable("www_news")->order("id desc")->limit(10)->select();
		
		$this->view->assign("newslist",$newslist);
		$this->view->assign("zplist",$zplist);
		$this->view->assign("jllist",$jllist);
		$html = $this->view->render("index/index.php");
		
		echo jhtml($html);
		
		//$job_m = $this->php->M("job");
		//$job_m->index();
	
	}

	function news() {

		$this->php->loaddb()->loadview()->helper("function")->helper("newsurl")->init();
		$id = intval($_GET["id"]);

		$vo = $this->php->M("news")->news_find($id);
		$this->view->assign("vo",$vo);
		$html = $this->view->render("index/news.php");
		echo jhtml($html);
	}
	
	/*
		招聘搜索页面
		性能不行，以后一定改 2011-1-30
	*/
	function zhaopin () {
	
		$this->php->loadview()->loaddb()->helper("function")->helper("newsurl")->init();
		$M = $this->php->M("job");
		$M->job_tree();
		$where = $M->job_soget();
		$url = $M->job_so_geturl();
		
		
		
		//加载分页类
		include 'Pagination/Pagination.php';
		include 'Pagination/PaginationConfig.php';
		$page = !empty($_GET['p']) ? (int)$_GET['p'] : 1;

		$nu = $this->db->settable("job_zhaopin")->where($where)->total();
		$pagesize=30;


		//初始化分页对象
		$pagination = new LtPagination;
		$pagination->conf->total_rows = $nu; //总数
		$pagination->conf->cur_page = $page; //当前页
		$pagination->conf->page_size = $pagesize; //每页显示数
		//$pagination->conf->base_url = 'newslist-'.$id.'-:page'.'.pl'; // :page会自动被替换掉
		$pagination->conf->base_url = "index.php?a=zhaopin&p=:page".$url;
		$pagination->init();
		$pageurl = $pagination->pages;


		//分页起始参数
		$climit=($page-1)*$pagesize;
		$list=$this->db->where($where)->limit($climit,$pagesize)->select();
		
		
		$this->view->assign("pageurl",$pageurl);
		$this->view->assign("list",$list);
		$html = $this->view->render("index/zhaopin.php");
		
		echo jhtml($html);
		
	}
	
	function jianli() {
	
		$this->php->loadview()->loaddb()->helper("function")->helper("newsurl")->init();
		$M = $this->php->M("job");
		$M->job_tree();
		$where = $M->job_soget();
		$url = $M->job_so_geturl();
		
		
		
		//加载分页类
		include 'Pagination/Pagination.php';
		include 'Pagination/PaginationConfig.php';
		$page = !empty($_GET['p']) ? (int)$_GET['p'] : 1;

		$nu = $this->db->settable("job_jianli")->where($where)->total();
		$pagesize=30;


		//初始化分页对象
		$pagination = new LtPagination;
		$pagination->conf->total_rows = $nu; //总数
		$pagination->conf->cur_page = $page; //当前页
		$pagination->conf->page_size = $pagesize; //每页显示数
		//$pagination->conf->base_url = 'newslist-'.$id.'-:page'.'.pl'; // :page会自动被替换掉
		$pagination->conf->base_url = "index.php?a=jianli&p=:page".$url;
		$pagination->init();
		$pageurl = $pagination->pages;


		//分页起始参数
		$climit=($page-1)*$pagesize;
		$list=$this->db->where($where)->limit($climit,$pagesize)->select();
		
		$this->view->assign("pageurl",$pageurl);
		$this->view->assign("list",$list);
		$html = $this->view->render("index/jianli.php");
		
		echo jhtml($html);
	
	}
	
	

	
	//选择进入哪个管理界面 个人 或 企业
	function xz() {
	
		
	
		
		if(C("misc.debug")) {
	
			$this->php->session()->loaddb()->loadview()->helper("function")->init();
			$this->session->openstart=1;
			$this->session->openid = "aaaaaaaaaaajlsjdfkljskldfjsdfdfkdfjksdf";
			
			
			
			$user = $this->php->M("user");
			$user->userindex($this->session->openid);
			
			$html = $this->view->render("index/xz.php");
			
			echo jhtml($html);
			
			
		}else {
		
			$this->php->session()->loadview()->helper("function")->init();
			
			if(empty($this->session->openstart)){
		
				$this->php->redirect(C("web.www")."/oauth/qq_auth.php");
			}else {
			
				$html = $this->view->render("index/xz.php");
				
				echo jhtml($html);
			}
		
		
		}
		
	}
	
	function zp () {
		$id = (int)$_GET["id"];
		if($id == 0) exit();
		
		
		$this->php->loaddb()->loadview()->helper("function")->init();
		
		$vo = $this->db->settable("job_zhaopin")->where("id=".$id)->find();
		if(!$vo) exit();
		
		$userid = $vo["userid"];
		$user = $this->db->settable("www_qiye")->where("userid=".$userid)->find();
		
		$this->view->assign("vo",$vo);
		$this->view->assign("user",$user);
		
		//$this->php->view->display("index/zp.php");
		
		
		//-----------------------------
		$this->db->settable("www_tree")->init();
		$list = $this->php->db->select();
		foreach($list as $key) {
			$vokey[$key["id"]] = $key["title"];
		}
		$this->view->assign("vokey",$vokey);
		//-----------------------------
		
		
		
		
		
		
		
		//$this->view->assign("conf",$this->php->config);
		$html = $this->view->render("index/zp.php"); 
		echo jhtml($html);
	
	}
	
	function jl() {
	
		$this->php->loaddb()->loadview()->helper("function")->init();
	
		$id=(int)$_GET["id"];
		if($id==0) exit("error 0");
		
		
		$vo = $this->db->settable("job_jianli")->where("id =".$id)->find();
		if(!$vo) exit("error 1");
		
		$this->db->settable("www_tree")->init();
		$diqu = $this->db->where("pid=6")->select();
		$jingyan = $this->db->where("pid=7")->select();
		$xinzi = $this->db->where("pid=8")->select();
		$xueli = $this->db->where("pid=26")->select();
		
		
		$this->view->assign("diqu",$diqu);
		$this->view->assign("jingyan",$jingyan);
		$this->view->assign("xinzi",$xinzi);
		$this->view->assign("xueli",$xueli);
		$this->view->assign("vo",$vo);
		$html = $this->php->view->render("index/jl.php");
		echo jhtml($html);
	
	}
	
	function phone() {
	
		$id=(int)$_GET["id"];
		$this->php->loaddb()->loadview()->session()->helper("function")->init();
		
		$vo = $this->db->settable("job_jianli")->where(array('id'=>$id))->find();
		
		if(empty($this->session->openstart)) {
			$this->php->redirect(C("web.www"),5,"请先登录，可以直接用qq登录，很方便，5秒后跳转到首页");
		}else {
			echo "<h1>";
			echo "电话 : ";
			echo h($vo['phone']);
			echo "</h1>";
		}
	
	}
	
	
	function qiye() {
	
		$id = (int)$_GET["id"];
		
		
		$this->php->loaddb()->loadview()->helper("function")->helper("newsurl")->init();
		
		$vo = $this->db->settable("www_qiye")->where("userid=".$id)->find();
		if(!$vo) exit();
		
		$zhaopin_list = $this->db->settable("job_zhaopin")->where("userid = ".$id)->select();
		
		$this->php->view->assign("vo",$vo);
		$this->php->view->assign("zhaopin_list",$zhaopin_list);
		
		
		$html = $this->php->view->render("index/qiye.php");
		echo jhtml($html);
		
		
		
	}
	
	
	function bye() {
	
		$this->php->session()->init();
	
	
		$_SESSION=array();
		unset($this->session);
		session_destroy();


		$this->php->redirect(C("web.www"));
	
	}
	
	function __destruct () {
	
		
		$debug = C("misc.debug");
		if(empty($debug)) exit();
		
		
		if(!empty($this->php->db)) {
			$str = $this->php->db->getMsg();
			echo "<hr />";
			echo $str;
		}
		
	
	
	}

}